package com.heima.netty.async;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * JDK 的 Future , 一般跟线程池配合使用
 * @author ZhengDp
 * @Date 2023/6/24 22:07
 */
@Slf4j
public class JdkFutureTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService service = Executors.newFixedThreadPool(1);
        Future<Integer> future = service.submit(() -> {
            try {
                log.info("Calculate");
                Thread.sleep(1000);
                return 50;
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        log.info("Main");
        Integer integer = future.get();
        log.info("Result : {}" , integer);
    }
}
